package com.songshan.filter;

import com.songshan.bean.User;

/**
 * @author feb
 * @date 2024/6/18
 * @Description: 当前登录用户上下文对象
 */
public class UserContext {


  private static final ThreadLocal<User> context = new ThreadLocal<>();

  /**
   * 存放用户信息
   */
  public static void set(User userInfo) {
    context.set(userInfo);
  }

  /**
   * 获取用户信息
   */
  public static User get() {
    return context.get();
  }

  /**
   * 清除当前线程内引用，防止内存泄漏
   */
  public static void remove() {
    context.remove();
  }
}
